package org.yray.sip.creator;


import org.yray.sip.base.MsgEle;
import org.yray.sip.server.SipSession;

public class RegisterCreator extends MessageCreator {
    /***z9hG4bK
     * REGISTER sip:172.168.200.78:5060 SIP/2.0
     * Via: SIP/2.0/UDP 172.130.13.31:61002;rport;branch=z9hG4bKPj0b9dc60ff7a7471aa77b8ecd727fddce
     Route: <sip:172.168.200.78:5060;lr>
     Max-Forwards: 70
     From: "78004" <sip:78004@172.168.200.78>;tag=b5da0090e681499eb2c956b184148c6f
     To: "78004" <sip:78004@172.168.200.78>
     Call-ID: 54aa5b12c90044db9213c14e0397b12e
     CSeq: 43035 REGISTER
     User-Agent: MicroSIP/3.20.3
     Contact: "78004" <sip:78004@172.130.13.31:61002;ob>
     Expires: 300
     Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
     Content-Length:  0
     * @return
     */
    @Override
    public String createMsg(SipSession session){
        StringBuilder sb = new StringBuilder();
        sb.append("REGISTER sip:"+ session.getSipIpPort()+" SIP/2.0").append(MsgEle.LINE_SEPARATOR);
        sb.append("Via: SIP/2.0/UDP "+ session.getLocalIpPort()+";rport;branch="+session.getBranch()).append(MsgEle.LINE_SEPARATOR);
        sb.append("Route: <sip:"+session.getSipIpPort()+";lr>").append(MsgEle.LINE_SEPARATOR);
        sb.append("Max-Forwards: 70").append(MsgEle.LINE_SEPARATOR);
        sb.append("From: "+session.getSipExtIpName()+";tag="+session.getTag()).append(MsgEle.LINE_SEPARATOR);
        sb.append("To: "+session.getSipExtIpName()).append(MsgEle.LINE_SEPARATOR);
        sb.append("Call-ID: "+session.getCallId()).append(MsgEle.LINE_SEPARATOR);
        sb.append("CSeq: "+session.getCseq()+" REGISTER").append(MsgEle.LINE_SEPARATOR);
        sb.append("User-Agent: ROBOT NO1").append(MsgEle.LINE_SEPARATOR);
        sb.append("Contact: "+session.getContact()).append(MsgEle.LINE_SEPARATOR);
        sb.append("Expires: 600").append(MsgEle.LINE_SEPARATOR);
        sb.append("Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS").append(MsgEle.LINE_SEPARATOR);
        sb.append(session.getAuthorization()==null?"":session.getAuthorization()+MsgEle.LINE_SEPARATOR);
        sb.append("Content-Length:  0").append(MsgEle.LINE_SEPARATOR);
        sb.append(MsgEle.LINE_SEPARATOR);
        return sb.toString();
    }


}
